// pages/student/live-room/live-room.js
import { courses } from '../../../utils/mockData.js'

Page({
  data: {
    course: null,
    isLive: true,
    liveTime: '19:00',
    viewers: 1234,
    messages: [],
    inputValue: ''
  },
  onLoad(options) {
    const courseId = parseInt(options.courseId)
    const course = courses.find(c => c.id === courseId)
    if (course) {
      this.setData({ course })
    }
  },
  onShow() {
    this.startLive()
  },
  onHide() {
    this.stopLive()
  },
  startLive() {
    // 模拟直播开始
    wx.setNavigationBarTitle({
      title: this.data.course.title + ' - 直播中'
    })
  },
  stopLive() {
    // 清理资源
  },
  sendMessage() {
    const { inputValue, messages } = this.data
    if (!inputValue.trim()) return
    
    const newMessage = {
      id: Date.now(),
      user: '我',
      text: inputValue,
      time: new Date().toLocaleTimeString()
    }
    
    this.setData({
      messages: [...messages, newMessage],
      inputValue: ''
    })
  },
  handleInput(e) {
    this.setData({
      inputValue: e.detail.value
    })
  },
  onShare() {
    wx.showShareMenu({
      withShareTicket: true
    })
  }
})
